import axios from 'axios';
import { operationCtx } from "../../../utils/auth";
import store from "@/store";
import { httpBehaviorUrl, httpComputedUrl } from "@/utils/http";

// const apiUrl = 'http://www.x3-clover.com/apiv2/';
// const apiUrlReport = 'http://www.x3-clover.com/apiv2/';

//南京测试环境
//后台管理
const apiUrl = httpBehaviorUrl + '/backend/behavior/';
//后台计算
const apiUrlReport = httpComputedUrl + '/backend/compute/';

// post
export function postAction(url, parameter,t) {
  parameter['operationCtx'] = operationCtx;
  if (parameter['req']) {
		parameter['req']['appId'] = store.state.global.appId;
		parameter['req']['requestId'] = require('node-uuid').v1();
	}
  return axios({url: url, method: 'post', data: parameter});
}


//事件列表
const thinglList = (params) => postAction(apiUrl + 'events/all', params);

//属性列表
const propertyList = (params) => postAction(apiUrl + `property/properties`, params);

//属性值查询
const valueList = (params) => postAction(apiUrl + "property/values", params);



// 获取漏斗列表
// const getFunnelList = (params) => postAction(apiUrl + 'funnels/funnel/list', params);
const getFunnelList = (params) => postAction(apiUrl + 'funnel/list/v2', params);

// 获取漏斗详情
// const getFunnelDetail = (params) => postAction(apiUrl + 'funnels/funnel/detail', params);
const getFunnelDetail = (params) => postAction(apiUrl + 'funnel/query/v2', params);

//漏斗创建
// const funnelCreate = (params) => postAction(apiUrl + 'funnels/funnel/create', params);
const funnelCreate = (params) => postAction(apiUrl + 'funnel/add/v2', params);

//漏斗修改
// const changeList = (params) => postAction(apiUrl + 'funnels/funnel/update', params);
const changeList = (params) => postAction(apiUrl + 'funnel/update/v2', params);


//漏斗分析——保存——书签
//分析书签（新建）
const bookmarkCreate = (params) => postAction(apiUrl + 'bookmarks/bookmark/create', params);
//分析书签（修改）
const bookmarkUpdate = (params) => postAction(apiUrl + 'bookmarks/bookmark/update', params);


// 漏斗分析计算
const funnelReportRes = (params) => postAction(apiUrlReport + 'funnels/report', params);


export {
  getFunnelList, //获取漏斗下拉选项列表
  //getPropertiesEvents, //获取【按 xx 条件查看】下拉菜单选项列表
  funnelReportRes, //漏斗需要展示的图表内容
  funnelCreate, //漏斗创建
  thinglList, //事件列表
  propertyList, //属性列表
  valueList,                      //属性值查询（没数据）
  changeList,                       //漏斗修改（编辑）
  getFunnelDetail, // 获取漏斗详情
  bookmarkCreate,          //分析书签（新建）
  bookmarkUpdate,           //分析书签（修改）
  //bookmarkDetail            //分析书签（详情）
};
